<?php
  include "counter.php";
?>
<html>
<head>
<!-- Attempt to get a half-hour refresh rate -->
<meta http-equiv="Refresh" content="1800">
<?php pagehead("Hourly statistics", "head") ?>
</head>

<body>
<?php pagetop("Linux Counter Statistics") ?> 
This is where I keep statistics about how well the
counter runs. It's always going to be half baked.
<p>
See also the <a href="stats.php">per-day statistics</a>
<p>
Statistics at <?php echo gmstrftime ("%b %d %Y %H:%M:%S",time()) ?>:<br>
<?php
if (!$days = $counter->get_input('days', 'number', 'get|post')) {
   $days = 1;
   $hours = 24;
} else {
   $hours = $days * 24;
}

echo "New persons last $hours hours: ";
echo dbcount("persons", "f_ctime > date_sub(now(), interval $days day)");
echo "<br>";
echo "Updated persons last $hours hours: ";
echo dbcount("persons", "f_mtime > date_sub(now(), interval $days day) and f_mtime <> f_ctime");
echo "<br>";
echo "Logins last $hours hours: ";
echo dbcount("users", "logintime > date_sub(now(), interval $days day)");
echo "<br>";
?>

<h2>Number of visitors per hour, last 3 days</h2>
<img src="visitorshour.png">
<h2>Number of operations per hour, last 3 days</h2>
<img src="byhour.png">

<h2>Number of Web accesses per hour, last 3 days</h2>
<img src="wwwbyhour.png">

<h2>Busiest countries for update and registration</h2>
For the last <?php echo $hours?> hours

<table border>
   <tr>
       <td>
       <font size="4"><b>Registrations</b></font>
       <table>
          <tr>
              <th>Count</th>
              <th>CC</th>
              <th align=left>Country</th>
          </tr>
<?php 
  $query = mysql_query('SELECT COUNT(*) AS c, country, places.longname FROM persons, places WHERE persons.f_ctime > DATE_SUB(NOW(), INTERVAL '. $days .' DAY) AND places.name = country GROUP BY country ORDER BY c desc LIMIT 10');
  while ($arr = mysql_fetch_row($query)) {
?>
          <tr>
              <td><?php echo $arr[0] ?></td>
              <td><?php echo $arr[1] ?></td>
              <td><?php echo $arr[2] ?></td>
          </tr>
<?php
  }
?>
       </table>
       </td>
       <td>
       <font size="4"><b>Updates</b></font>
       <table>
          <tr>
              <th>Count</th>
              <th>CC</th>
              <th align=left>Country</th>
          </tr>
<?php
  $query = mysql_query('SELECT COUNT(*) AS c, country, places.longname FROM persons, places WHERE persons.f_mtime > DATE_SUB(NOW(), INTERVAL '. $days.' DAY) AND persons.f_mtime <> persons.f_ctime AND places.name = country GROUP BY country ORDER BY c desc LIMIT 10');
  while ($arr = mysql_fetch_row($query)) {
?>
          <tr>
              <td><?php echo $arr[0] ?></td>
              <td><?php echo $arr[1] ?></td>
              <td><?php echo $arr[2] ?></td>
          </tr>
<?php
  }
?>
       </table>
       </td>
   </tr>
</table>
<?php pagebottom() ?>
</body>
</html>
